package logic

import (
	"context"
	"houses_srv/housesclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateHouseLogic {
	return &UpdateHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateHouseLogic) UpdateHouse(req *types.UpdateHouserequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.HousesSrv.UpdateHouse(l.ctx, &housesclient.UpdateHouseRequest{
		HouseId:   int64(req.HouseId),
		Title:     req.Title,
		Image:     req.Image,
		Price:     int64(req.Price),
		Fool:      float32(req.Fool),
		HouseType: req.HouseType,
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "房源信息修改成功",
		Code: 200,
		Data: update,
	}, nil
}
